<template>
	<view>
        <!-- 公共组件-每个页面必须引入 -->
        <public-module></public-module>
	
    <view class="u-padding-35">

      <u--form label-position="top" labelWidth="auto">

		<view v-if="model.agent_id>0&&userInfo.grade==4" style="color:red">
			承接城市：{{model.region.region_fullname}}
		</view>
        <u-form-item class="form-item" label="选择承接城市" v-else>
			<addressd @changes="area" :addressd="addressData"></addressd>
        </u-form-item>
        <u-form-item class="form-item" label="您的名字" prop="realname">
          <u-input v-model="model.realname" placeholder="真实姓名" type="text" :disabled="model.agent_id>0&&userInfo.grade!=4?true:false"/>
        </u-form-item>
		
        <u-form-item class="form-item" label="详细地址" prop="realname">
          <u-input v-model="model.address" placeholder="详细地址信息" type="text" :disabled="model.agent_id>0&&userInfo.grade!=4?true:false"/>
        </u-form-item>

        <u-form-item class="form-item" label="联系人电话" prop="realname">
          <u-input v-model="model.mobile" placeholder="业务联系人电话" type="text" :disabled="model.agent_id>0&&userInfo.grade!=4?true:false"/>
        </u-form-item>
      </u--form>

	  <view v-if="model.agent_id>0&&userInfo.grade!=4" style="color:red">
			<center>申请正在审核中</center>
	  </view>
      <u-button type="primary" @click="sumbitsaleer" v-else>
		  <span v-if="userInfo.grade!=4">申请</span><span v-else>修改</span>
	</u-button>
    </view>

	</view>
</template>

<script>
import { mapState, mapMutations } from 'vuex';

import { api_agent_applysale,api_agent_info } from '@/config/api.js';
import addressd from "@/components/jm-address/jm-address.vue"
export default {
    components: {
        addressd
    },
	data() {
		return {
			addressData:{
				region_fullname:'',
				region_id:'',
				addr_id:'',
				consignee:'',
				mobile:'',
				address:'',
				is_default:false,
				region_idpath:[1,11,0],
				region_namepath:[this.$t('select1'),this.$t('select2'),this.$t('select3')]
			},
			addr_id:"",
			model:{}
		};
	},
	computed:{
	    ...mapState(['userInfo']),
	},
	onLoad() {
		this.get_agentinfo()
	},
	methods: {
		area(e) {
			this.region_fullname=e.region_fullname
			this.addressData.region_id=e.region_id
			this.model.region_id=e.region_id
        },
		sumbitsaleer() {
			if(this.addressData.region_id==''){
				uni.$u.toast(this.$t('noselect'))
				return;
			}
			api_agent_applysale(this.model).then((res) => {
				if (res.agent_id>0){
					this.$tools.goJump('/pages/user/result',{type:1},'','launch')
				}
			}).catch((e) => {});
        },
		get_agentinfo() {
			api_agent_info().then((res) => {
				console.log(res)
				this.model=res
				if (res.agent_id>0)this.addressData=res.region
			}).catch((e) => {});
        },
		
		
		
	},
};
</script>

<style lang="scss" scoped>

</style>
